package framework;

import java.util.List;

import org.openems.entity.ChoiceEntity;
import org.openems.entity.Entity;
import org.openems.entity.Key;
import org.openems.entity.ListEntity;
import org.openems.entity.MarkerEntity;
import org.openems.entity.NumericEntity;
import org.openems.entity.TraceEntity;


public class AccessorHelperImpl implements AccessorHelper {

	private Accessor accessor;

	public AccessorHelperImpl(Accessor accessor) {
		this.accessor = accessor;
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#getDoubleValue(org.openems.entity.Key)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#getDoubleValue(org.openems.entity.Key)
	 */
	@Override
	public Double getDoubleValue(Key key) {
		return ((NumericEntity)accessor.get(key)).getValue();
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#setDoubleValue(org.openems.entity.Key, java.lang.Double)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#setDoubleValue(org.openems.entity.Key, java.lang.Double)
	 */
	@Override
	public void setDoubleValue(Key key, Double value) {
		NumericEntity entity = (NumericEntity)accessor.get(key);
		entity.setValue(value);
		accessor.put(entity);
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#getAccessor()
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#getAccessor()
	 */
	@Override
	public Accessor getAccessor() {
		return this.accessor;
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#getSelectedItem(org.openems.entity.Key)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#getSelectedItem(org.openems.entity.Key)
	 */
	@Override
	public String getSelectedItem(Key key) {
		ChoiceEntity entity = (ChoiceEntity)accessor.get(key);
		return entity.getValueText();
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#setSelectedItem(org.openems.entity.Key, java.lang.String)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#setSelectedItem(org.openems.entity.Key, java.lang.String)
	 */
	@Override
	public void setSelectedItem(Key key, String value) {
		ChoiceEntity entity = (ChoiceEntity)accessor.get(key);
		entity.setValueText(value);
		this.accessor.put(entity);
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#addChild(org.openems.entity.Key, org.openems.entity.Entity)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#addChild(org.openems.entity.Key, org.openems.entity.Entity)
	 */
	@Override
	public void addChild(Key key, Entity child) {
		ListEntity entity = (ListEntity)accessor.get(key);
		this.accessor.put(child);
		entity.getKeys().add(child.getKey());
		this.accessor.put(entity);
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#getKeyList(org.openems.entity.Key)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#getKeyList(org.openems.entity.Key)
	 */
	@Override
	public List<Key> getKeyList(Key key) {
		return ((ListEntity)this.accessor.get(key)).getKeys();
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#getMarkerX(org.openems.entity.Key)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#getMarkerX(org.openems.entity.Key)
	 */
	@Override
	public Double getMarkerX(Key key) {
		return ((MarkerEntity)this.accessor.get(key)).getValue();
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#getTraceValues(org.openems.entity.Key)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#getTraceValues(org.openems.entity.Key)
	 */
	@Override
	public Double[] getTraceValues(Key key) {
		return ((TraceEntity)this.accessor.get(key)).getData();
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#getTraceXmax(org.openems.entity.Key)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#getTraceXmax(org.openems.entity.Key)
	 */
	@Override
	public Double getTraceXmax(Key key) {
		return ((TraceEntity)this.accessor.get(key)).getHorizontalMax();
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#getTraceXmin(org.openems.entity.Key)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#getTraceXmin(org.openems.entity.Key)
	 */
	@Override
	public Double getTraceXmin(Key key) {
		return ((TraceEntity)this.accessor.get(key)).getHorizontalMin();
	}

	/* (non-Javadoc)
	 * @see framework.ResolverHelper#setMarkerY(org.openems.entity.Key, java.lang.Double)
	 */
	/* (non-Javadoc)
	 * @see framework.AccessorHelper#setMarkerY(org.openems.entity.Key, java.lang.Double)
	 */
	@Override
	public void setMarkerY(Key key, Double yvalue) {
		MarkerEntity o = ((MarkerEntity)this.accessor.get(key));
		o.setYvalue(yvalue);
		this.accessor.put(o);
	}

	@Override
	public Double getMarkerY(Key key) {
		return ((MarkerEntity)this.accessor.get(key)).getYvalue();
	}

	@Override
	public String getMarkerText(Key key) {
		return ((MarkerEntity)this.accessor.get(key)).getText();
	}

	@Override
	public void removeListItem(Key key) {
		
	}

}
